% Paper: E- Monetary Theory  (2nd edition)
% Author: Duong Ngotran
% Graph: Crisis - Large scale asset purchase

%----------------------------------------------------------------------------
% Some Parameters
%----------------------------------------------------------------------------
T = 301;    %Number of periods 
var_foc = 29;      % Number of variables in one period
pos_value = 3;     % Position of var_value in A
truc = (-1):(T-2);         % Horizontal axis when drawing with level
spline_truc = (-1):(1/4):(T-2);     %Horizontal axis when drawing with spline 
size_struc = 1201;  % size of spline truc
deltab = 0.5;

%----------------------------------------------------------------------------
% ZLB during 20 periods
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_zlb_duration_20.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_20= rf_t;
rh_20= rh_t;
rrf_20 = rrf_t;
ql_20= AP_S(mapp('ql'),:);
pie_20= AP_S(mapp('pie'),:);
y_20 = AP_S(mapp('y'),:);
gm_20 = s_growth_M;
m_20 = AP_S(mapp('m'),:);
n_20 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
% ZLB during 40 periods
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_zlb_duration_40.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_40= rf_t;
rh_40= rh_t;
rrf_40 = rrf_t;
ql_40= AP_S(mapp('ql'),:);
pie_40= AP_S(mapp('pie'),:);
y_40 = AP_S(mapp('y'),:);
gm_40 = s_growth_M;
m_40 = AP_S(mapp('m'),:);
n_40 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
% ZLB during 80 periods
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_zlb_duration_80.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_80= rf_t;
rh_80= rh_t;
rrf_80 = rrf_t;
ql_80= AP_S(mapp('ql'),:);
pie_80= AP_S(mapp('pie'),:);
y_80 = AP_S(mapp('y'),:);
gm_80 = s_growth_M;
m_80 = AP_S(mapp('m'),:);
n_80 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
%Figure
%----------------------------------------------------------------------------
set(groot, 'DefaultLegendInterpreter', 'latex')

figure('Name', 'Federal Funds Rate');
plot(truc, rf_20, truc, rf_40);
line_fewer_markers(truc, rf_80, 15, '-rs');
leg = legend('$R^f$ - LSAP20', '$R^f$ - LSAP40', '$R^f$ - LSAP80', 'location', 'best');

figure('Name', 'Real rate of borrowing');
plot(truc, rh_20, truc, rh_40);
line_fewer_markers(truc, rh_80, 15, '-rs');
leg = legend('$r^h$ - LSAP20', '$r^h$ - LSAP40', '$r^h$ - LSAP80', 'location', 'best');

figure('Name', 'Money Supply');
plot(spline_truc, m_20, spline_truc, m_40);
line_fewer_markers(spline_truc, m_80, 15, '-rs');
leg = legend('$m$ - LSAP20', '$m$ - LSAP40', '$m$ - LSAP80', 'location', 'best');

figure('Name', 'Output');
plot(spline_truc, y_20, spline_truc, y_40);
line_fewer_markers(spline_truc, y_80, 15, '-rs');
leg = legend('$y$ - LSAP20', '$y$ - LSAP40', '$y$ - LSAP80', 'location', 'best');

figure('Name', 'Inflation');
plot(spline_truc, pie_20, spline_truc, pie_40);
line_fewer_markers(spline_truc, pie_80, 15, '-rs');
leg = legend('$\pi$ - LSAP20', '$\pi$ - LSAP40', '$\pi$ - LSAP80', 'location', 'best');

figure('Name', 'Reserves');
plot(spline_truc, n_20, spline_truc, n_40);
line_fewer_markers(spline_truc, n_80, 15, '-rs');
leg = legend('$n$ - LSAP20', '$n$ - LSAP40', '$n$ - LSAP80', 'location', 'best');
        
        
        
        
        
        
        
        